//
//  VideoBtnView.m
//  for_test
//
//  Created by Carlson Lee on 2017/4/6.
//  Copyright © 2017年 Carlson Lee. All rights reserved.
//

#import "VideoBtnView.h"

@interface VideoBtnView ()

@property(nonatomic, strong)UIButton* leftBtn;
@property(nonatomic, strong)UIButton* rightBtn;

@end

@implementation VideoBtnView

- (instancetype)initWithBtnType:(BTN_TYPE )type
{
    if(self = [super init]){
        self.type = type;
    }
    return self;
}

- (void)setType:(BTN_TYPE)type
{
    _type = type;
    NSString* str1, *str2;
    if(_type == BTN_TYPE_READY){
        str1 = @"开始朗读";
    }else if (_type == BTN_TYPE_FOLLOW){
        str1 = @"朗读中...";
    }else if (_type == BTN_TYPE_OVER){
        str1 = @"重新朗读";
        str2 = @"确认无误";
    }else{
    
    }
    
    if(str1){
        [self.leftBtn setTitle:str1 forState:UIControlStateNormal];
    }
    if(str2){
        [self.rightBtn setTitle:str2 forState:UIControlStateNormal];
    }
}

- (UIButton *)leftBtn
{
    if(!_leftBtn){
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_leftBtn];
        _leftBtn.tag = 0;
        [self.leftBtn.layer setCornerRadius:3.0];
        [self.leftBtn.layer setMasksToBounds:YES];
        [self.leftBtn.titleLabel setFont:SDFont(16, FONT_TYPE_REGULAR)];
        [_leftBtn addTarget:self action:@selector(btnResponse:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftBtn;
}

- (UIButton *)rightBtn
{
    if(!_rightBtn){
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_rightBtn];
        _rightBtn.tag = 1;
        [self.rightBtn.layer setCornerRadius:3.0];
        [self.rightBtn.layer setMasksToBounds:YES];
        [self.rightBtn.titleLabel setFont:SDFont(16, FONT_TYPE_REGULAR)];
        [_rightBtn addTarget:self action:@selector(btnResponse:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightBtn;
}

- (void)btnResponse:(UIButton* )sender
{
    if(_resBlock){
        _resBlock(_type, sender.tag);
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat f_x = (UIFrameW(self)-270*ScaleX)/2;
    CGRect lrect = CGRectMake((UIFrameW(self)-120*ScaleX)/2, (UIFrameH(self)-44*ScaleX)/2, 120*ScaleX, 44*ScaleX);
    CGRect rrect = lrect;
    if(_type == BTN_TYPE_OVER){
        lrect = CGRectMake(f_x, (UIFrameH(self)-44*ScaleX)/2, 120*ScaleX, 44*ScaleX);
        rrect = CGRectMake(CGRectGetMaxX(lrect)+30*ScaleX, CGRectGetMinY(lrect), 120*ScaleX, 44*ScaleX);
    }
    
    self.leftBtn.frame = lrect;
    if(_type == BTN_TYPE_OVER){
        self.rightBtn.frame = rrect;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
